<?php

namespace Database\Factories;

use App\Models\Alarm;
use App\Models\ESCluster;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
 */
class OperationFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $type = $this->faker->randomElement(['App\Models\Alarm', 'App\Models\EarlyAlarm']);

        return [
            'user_name' => $this->faker->unique()->name(),
            'user_id' => $this->faker->randomElement(User::all()->pluck('id')),
            'type' => $this->faker->randomElement(['电池', '箱体']),
            'description' => $this->faker->randomElement(['电池过热问题检测', 'SOH数值异常']),
            'status' => $this->faker->randomElement(['处理中', '已完成']),
            'alarm_type' =>  $type,
            'alarm_id' =>  $this->faker->randomElement(app()->make($type)::all()->pluck('id')),
            'e_s_cluster_id' =>  $this->faker->randomElement(ESCluster::all()->pluck('id')),
            'time' => $this->faker->dateTimeBetween($startDate = '-10 days', $endDate = '-1 days'),
        ];
    }
}
